package com.andaily.web.controller.mobile.log;

import com.andaily.domain.dto.log.LogDetailsDto;
import com.andaily.domain.dto.log.LogOverviewDto;
import com.andaily.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @RequestMapping("overview")
    public String overview(LogOverviewDto overviewDto, ModelMap model) throws Exception {
        overviewDto = logService.loadLogOverview(overviewDto);
        model.addAttribute("overviewDto", overviewDto);
        return "log/log_overview";
    }

    @RequestMapping("overview/more")
    public String more(LogOverviewDto overviewDto, ModelMap model) throws Exception {
        overviewDto = logService.loadLogOverview(overviewDto);
        model.addAttribute("overviewDto", overviewDto);
        return "log/log_overview_more";
    }

    @RequestMapping("details/{guid}")
    public String details(@PathVariable() String guid, ModelMap model) throws Exception {
        LogDetailsDto logDetails = logService.loadLogDetails(guid);
        model.addAttribute("logDetails", logDetails);
        return "log/log_details";
    }

    @RequestMapping("confirm_delete/{guid}")
    public String confirmDelete(@PathVariable() String guid, ModelMap model) throws Exception {
        model.addAttribute("guid", guid);
        return "log/log_confirm_delete";
    }

    @RequestMapping("delete/{guid}")
    public String delete(@PathVariable() String guid) throws Exception {
        logService.archiveLog(guid);
        return "redirect:../overview";
    }
}
